import * as React from "react";
import { Skeleton } from "@/components/ui/skeleton";
import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton";
import { getDocumentClassCodeGroups } from "@/lib/docu-list-rule/document-class/service";
import { DocumentClassTable } from "@/lib/docu-list-rule/document-class/table/document-class-table";

import { searchParamsDocumentClassCache } from "@/lib/docu-list-rule/document-class/validation";

interface IndexPageProps {
  searchParams: Promise<any>;
  params: Promise<{ lng: string; projectId: string }>;
}

export default async function IndexPage(props: IndexPageProps) {
  const searchParams = await props.searchParams;
  const { projectId } = await props.params;
  
  // 프로젝트 ID를 필터에 추가
  const searchParamsWithProject = {
    ...searchParams,
    projectId: projectId
  };

  const promises = Promise.all([
    getDocumentClassCodeGroups(
      searchParamsDocumentClassCache.parse(searchParamsWithProject)
    ),
  ]);

  return (
    <>

      <React.Suspense fallback={<Skeleton className="h-7 w-52" />}></React.Suspense>
      <React.Suspense
        fallback={
          <DataTableSkeleton
            columnCount={4}
            searchableColumnCount={1}
            filterableColumnCount={1}
            cellWidths={["10rem", "20rem", "10rem", "8rem"]}
            shrinkZero
          />
        }
      >
        <DocumentClassTable promises={promises} />
      </React.Suspense>
    </>
  );
}
